#include<iostream>
#include<string>
#include<string.h>
#include<assert.h>
#include<algorithm>
using namespace std;

namespace Mystring{
    class string{
    public:
        static const size_t npos=-1;
        //构造函数
        string(const char* str = "");
        //析构函数
        ~string();
        //拷贝构造函数
        string(const string&s);
        //赋值运算符重载
        string& operator=(const string&s);
        
        //c格式打印
        const char* c_str(){
            return _str;
        }

        //容量大小
        size_t size()
        {
            return _size;
        }
        size_t capacity()
        {
            return _capacity;
        }
        //扩容
        void reserve(size_t n);
        void resize(size_t n,char ch='\0');

        void clear(){
            _size=0;
            _str[_size]='\0';
        }

        //访问方式
        char& operator[](size_t pos){
            assert(pos<_size);
            return _str[pos];
        }
        char& at(size_t pos){
            assert(pos<_size);
            return _str[pos];
        }

        //迭代器
        typedef char* iterator;
        iterator begin() {
            return _str;
        }
        iterator end() {
            return _str+_size;
        }
        typedef const char* const_iterator;
        const_iterator begin()const {
            return _str;
        }
        const_iterator end()const {
            return _str+_size;
        }

        //修改
        void push_back(char ch);            
        void append(char ch);                
        void append(const char* str);        
        string& operator+=(char ch);         
        string& operator+=(const char* str); 
        void insert(size_t pos,size_t n,char ch);
        void insert(size_t pos,const char*str);
        void erase(size_t pos,size_t len=npos);

        //查找
        size_t find(char ch,size_t pos=0);
        size_t find(const char*str,size_t pos=0);

        //友元函数
        friend ostream& operator<<(ostream& out,const string&s);
        friend istream& operator>>(istream& in,string&s);


    private:
        int _size;
        int _capacity;
        char* _str;
    };

    //非string成员函数
    ostream& operator<<(ostream& out,const string&s);
    istream& operator>>(istream& in,string&s);
}


